package com.luodim.ruledemo.view;

import android.content.Context;
import android.graphics.Bitmap;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.luodim.ruledemo.R;
import com.luodim.ruledemo.utils.BaseUtils;

/**
 * Created by luodi on 2017/7/10.
 */

public class ContentView extends RelativeLayout {

    private ImageView mContainer;
    private int mParentW;
    private int mParentH;

    public ContentView(Context context) {
        this(context, null);
    }

    public ContentView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public ContentView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView();
    }

    private void initView() {
        View contentView = View.inflate(getContext(), R.layout.view_content, this);
        mContainer = (ImageView) contentView.findViewById(R.id.img_container);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        mParentW = widthMeasureSpec;
        mParentH = heightMeasureSpec;
    }

    public void setSrc(int resId) {
        Bitmap bmp = BaseUtils.bitmapSizeFit(getContext(), mParentW, mParentH, resId);
        if (bmp != null) mContainer.setImageBitmap(bmp);
    }
    
    public void setSrc(Bitmap bmp) {
        // TODO: 2017/7/10  
    }
}
